FROM registry.cn-hangzhou.aliyuncs.com/lxi-build/composer2:release AS composer

WORKDIR /app

COPY ./composer.json /app/composer.json
COPY ./composer.lock /app/composer.lock
COPY ./database /app/database
COPY ./app /app/app
COPY ./packages /app/packages

RUN set -ex; \
    \
    composer install \
        --no-dev \
#        --dry-run \
        --optimize-autoloader \
        --prefer-install=dist \
        --ignore-platform-reqs \
        --no-interaction \
        --no-scripts \
        --no-ansi;

FROM registry.cn-hangzhou.aliyuncs.com/lxi-build/php81-ng:release
COPY ./ /app
COPY --from=composer /usr/bin/composer /usr/bin/composer
COPY --from=composer /app/vendor /app/vendor

RUN set -ex; \
    \
    apk add vim; \
    mkdir -p storage; \
    mkdir -p storage/app; \
    mkdir -p storage/framework; \
    mkdir -p storage/logs; \
    mkdir -p storage/framework/sessions; \
    mkdir -p storage/framework/cache; \
    mkdir -p storage/framework/cache/data; \
    mkdir -p storage/framework/views; \
    chmod -R 777 storage; \
    chmod 777 bootstrap/cache; \
    php artisan route:cache;

STOPSIGNAL SIGQUIT

EXPOSE 9000

CMD ["php", "artisan", "serve", "--port=8000", "--host=0.0.0.0"]
